package com.b.sts.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.b.sts.entity.GraduateEntity;
import com.b.sts.entity.UserEntity;
import com.b.sts.mapper.GraduateMapper;
import com.b.sts.mapper.UserMapper;
import com.b.sts.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author boy
 * @since 2022/11/5
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {
    @Resource
    UserMapper mapper;
    @Resource
    GraduateMapper graduateMapper;

    @Override
    public UserEntity get(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public String getName(Integer id) {
        UserEntity user = this.get(id);
        return user != null ? user.getName() : "";
    }

    @Override
    public boolean isGraduate(UserEntity userEntity) {
        GraduateEntity graduateEntity = new GraduateEntity();
        BeanUtils.copyProperties(userEntity, graduateEntity);
        LambdaQueryWrapper<GraduateEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.setEntity(graduateEntity);
        List<GraduateEntity> list = graduateMapper.selectList(wrapper);
        return CollUtil.isNotEmpty(list);
    }

    @Override
    public boolean saveGraduateData(List<GraduateEntity> list) {
        for (GraduateEntity graduateEntity : list) {
            graduateMapper.insert(graduateEntity);
        }
        return false;
    }

}
